#include "recbox.h"
#include "ui_recbox.h"
#include "recboxitem.h"
#include <QStringLiteral>
#include <QIcon>
RecBox::RecBox(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::RecBox)
    , row(1)
    , col(4)
{
    ui->setupUi(this);

    RecBoxItem* item = new RecBoxItem();
    // QIcon icon(":/images/rec/001.png");
    // item->setStyleSheet("border-image: url(:/images/001.png)");
    // item->setText(QStringLiteral("每日推荐"));; // 显示类型转化
    // item->setImage(":/images/rec/005.png");
    ui->recListUpHLayout->addWidget(item);
}

RecBox::~RecBox()
{
    delete ui;
}

void RecBox::InitRecBoxUi(QJsonArray data, int row){
    if(2 == row){ // 如果是两行, 则当前RecBox 是 supplyMusicBox
        this->row = row;
        this->col = 8;
    }
    else{
        ui->recListDown->hide();
    }
    imageList = data;
    CreateRecBoxItem();
}

void RecBox::CreateRecBoxItem()
{
    for(int i = 0; i < col; ++i){
        RecBoxItem* item = new RecBoxItem();
        // 设置音乐图片 与 对应文本
        QJsonObject obj = imageList[i].toObject();
        item->setText(obj.value("text").toString());
        item->setImage(obj.value("path").toString());
        // qDebug() << obj.value("text").toString() << " " << obj.value("path").toString();
        // item->setText("001");
        // item->setImage(":/images/rec/001.png");
        ui->recListUpHLayout->addWidget(item);
    }

}
